package barbershop.com.dao.orders;

import barbershop.com.entity.orders.OrderItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface OrderItemDao extends JpaRepository<OrderItem, Integer> {
    @Modifying
    @Query(value = "update order_item set quantity=?1 where order_item_id=?2",
            nativeQuery = true)
    void updateQuantity(Integer quantity, Integer id);

    List<OrderItem> findAllByOrdersOrderId(Integer orderId);

    // 金额小计
    @Modifying
    @Query(value = "update order_item set sub_total_money=?1 where order_item_id=?2",
            nativeQuery = true)
    void updateSubTotalMoney(Double subTotal, Integer id);

}
